<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<jsp:useBean id="utilities" class="masterpiece.util.Utilities" scope="session" />    
<%@ page import="java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add User</title>
<link rel="stylesheet" type="text/css" href="css/default.css" />
</head>
<body>
<%@ include file="top_menu.jsp" %>
<% String epass = request.getParameter("epass").toLowerCase();%> <br>
<% String fname = request.getParameter("fname");%>	<br>
<% String initial = request.getParameter("initial");%> <br>
<% String lname = request.getParameter("lname");%> <br>
<% String role = request.getParameter("role").trim(); %>
<%ResultSet rset = utilities.getUsers();
    boolean flag = false;
	while (rset.next() && flag == false){
		if (rset.getString(1).equals(epass)){
			flag = true;
		}
	}
	if (flag){
		out.print("<p class=\"message error\">EPASS is all ready in the database</p>");
	}
	if (epass.isEmpty()){
		out.print("<p class=\"message error\">Must provide an epass</p>");
		flag = true;
	}
	if (fname.isEmpty()){
		out.print("<p class=\"message error\">Must provide first name</p>");
		flag = true;
	}
	if(lname.isEmpty()){
		out.print("<p class=\"message error\">Must privde last name</p>");
		flag = true;
	}
		if (!flag){		
			utilities.newUser(epass, fname, initial, lname, role);
			out.print("added to the data base");
			
		}else {
			out.print("<p class=\"message error\">Unable to add user to database</p>");
		}
	%>
	
</body>
</html>